package com.lc.reader.data.dao

import androidx.room.*
import com.lc.reader.data.model.Book
import kotlinx.coroutines.flow.Flow

@Dao
interface BookDao {
    
    @Query("SELECT * FROM books ORDER BY lastReadTime DESC")
    fun getAllBooks(): Flow<List<Book>>
    
    @Query("SELECT * FROM books WHERE id = :bookId")
    suspend fun getBookById(bookId: Long): Book?
    
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertBook(book: Book): Long
    
    @Update
    suspend fun updateBook(book: Book)
    
    @Delete
    suspend fun deleteBook(book: Book)
    
    @Query("DELETE FROM books WHERE id = :bookId")
    suspend fun deleteBookById(bookId: Long)
    
    @Query("UPDATE books SET currentPage = :currentPage, lastReadTime = :lastReadTime, readingProgress = :readingProgress WHERE id = :bookId")
    suspend fun updateReadingProgress(bookId: Long, currentPage: Int, lastReadTime: Long, readingProgress: Float)
}
